// Learn cc.Class:
//  - [Chinese] http://www.cocos.com/docs/creator/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/class/index.html
// Learn Attribute:
//  - [Chinese] http://www.cocos.com/docs/creator/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/reference/attributes/index.html
// Learn life-cycle callbacks:
//  - [Chinese] http://www.cocos.com/docs/creator/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/life-cycle-callbacks/index.html

cc.Class({
    extends: cc.Component,

    properties: {
        noticeDetailPop: cc.Prefab,   //通知公告详情界面
        circleSp: cc.Sprite, //推荐的标志图片
        labDec: cc.Label,  //公告内容
        labtime: cc.Label,  //时间日期
        _data: null,
    },

    onLoad: function(){
        this.node.on('touchstart',function(){
            var canvas =cc.find('Canvas');
            var noticeDetailPop =cc.instantiate(this.noticeDetailPop);
            noticeDetailPop.getComponent('notice_detail_pop').init(this._data);
            canvas.addChild(noticeDetailPop);           
        }.bind(this))
    },

    init: function(data){
        //cc.log('notice_item 列表数据',data);
        //显示内容
        if(data.IsRecommend){
            this.circleSp.node.active =true;
        }else{
            this.circleSp.node.active =false;
        }
        this.labDec.string = data.Title;

        var date =Utils.formateServiceDateStrToDate(data.Time);
        this.labtime.string = this.splitTwo(date.getFullYear())+'-'+this.splitTwo(date.getMonth() + 1)+'-'+ this.splitTwo(date.getDate());

        this._data = data;
    },

    splitTwo:function(num){
        return num.toString().length<2?"0"+num.toString():num.toString();
    },

    // update (dt) {},
});
